package com.wy.controller;

import com.wy.Service.DanyuanService;
import com.wy.pojo.Danyuan;
import com.wy.pojo.Louyv;
import com.wy.pojo.Reside;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/danyuan")
@CrossOrigin
public class DanyuanController {
    @Resource
    private DanyuanService danyuanServer;
    @GetMapping("/listAll")
    public List<Danyuan> search(){
        return danyuanServer.searchAll();
    }
    String msg;
    @GetMapping("/list")
    public List<Danyuan>seach(Integer louyvid){
        return danyuanServer.searchidAll(louyvid);
    }

    @GetMapping("/delete")
    public String delete(Integer id){
        try{
            danyuanServer.del(id);
            msg="删除成功";
        }catch (Exception e){
            msg="删除失败";
        }
        return msg;
    }

    @GetMapping("/add")
    public String add(Danyuan danyuan){
        try{
            danyuanServer.add(danyuan);
            msg="添加成功";
        }catch (Exception e){
            msg="添加失败";
        }
        return msg;
    }

    @GetMapping("/update")
    public String update(Danyuan danyuan){
        try{
            danyuanServer.add(danyuan);
            msg="修改成功";
        }catch (Exception e){
            msg="修改失败";
        }
        return msg;
    }
}
